//
//  UIButton+extision.swift
//  MyLottery
//
//  Created by wujunjie on 2018/7/18.
//  Copyright © 2018年 wujunjie. All rights reserved.
//

import UIKit

extension UIButton{
//    //便利构造器
    convenience init(image: String? = nil,backgroundImage:String? = nil,fontColor : UIColor = UIColor.darkGray, title:String,font:CGFloat = 13,target:Any,action:Selector ,event:UIControlEvents) {
        ///先完成自己的构造过程
        self.init()
        self.setTitle(title, for: .normal)
        self.titleLabel?.font = UIFont.systemFont(ofSize: font)
        self.setTitleColor(fontColor, for: .normal)
        if let image = image{
            self.setImage(UIImage(named: image), for: .normal)
            self.setImage(UIImage(named: "\(image)_highlighted"), for: .selected)
        }

        if let backgroundImage = backgroundImage {
            self.setBackgroundImage(UIImage(named: backgroundImage), for: .normal)
            self.setBackgroundImage(UIImage(named: "\(backgroundImage)_highlighted"), for: .highlighted)
        }
        self.sizeToFit()
        self.addTarget(target, action: action, for: .touchUpInside)
    }
}
